from zope.interface import implements

from meercat.solr.mapreduce.interfaces import ISolrProcessor

class CopyField(object):
    implements(ISolrProcessor)
    
    def __init__(self, source, destination, prefilter=None):
        self.source = source
        self.destination = destination
        self.prefilter=None
    
    def __call__(self, metadata):
        if self.source in metadata:
            if self.prefilter:
                metadata.setdefault(self.destination,
                                    []).extend(filter(self.prefilter,
                                                      metadata[self.source]))
            else:
                metadata.setdefault(self.destination,
                                    []).extend(metadata[self.source])